package cn.springcloud.fix.samples.mq.listener;

import cn.springcloud.fix.samples.config.RabbitConfig;
import com.alibaba.fastjson.JSON;
import com.rabbitmq.client.Channel;
import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.core.Message;
import org.springframework.amqp.core.MessageProperties;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.stereotype.Component;

import java.io.IOException;

@Slf4j
@Component
public class LoginListener {

    @RabbitListener(queues = RabbitConfig.LOGIN_LOG_QUEUE_NAME)
    public void consume(Message message, Channel channel) {
        try {
            log.info("message:{},channel:{}", JSON.toJSONString(message), JSON.toJSONString(channel));
            MessageProperties properties = message.getMessageProperties();
            long tag = properties.getDeliveryTag();
            // channel.basicAck(tag, false);// 消费确认
            channel.basicNack(tag, false, false);
        } catch (IOException e) {
            log.error(e.getMessage(), e);
        }
    }
}
